package com.yummy.security;

import java.io.Serializable;
import java.util.List;

import org.springframework.util.CollectionUtils;

public abstract class RespectableUser implements User,Serializable{
	
	private List<Permission> permissions;
	private List<Role> roles;

	/**
	 * 
	 */
	private static final long serialVersionUID = -4263087357988449569L;

	public List<Permission> getPermissions() {
		return permissions;
	}

	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	public boolean hasRole(String roleName) {
		if(CollectionUtils.isEmpty(roles)) {
			return false;
		}
		for(Role r : roles) {
			if(r.getName().equals(roleName)) {
				return true;
			}
		}
		return false;
	}

	public boolean hasPermission(PermissionMatcher permissionMatcher, String urlPath) {
		return permissionMatcher.match(permissions, urlPath);
	}

}
